<template>
  <div id="AllProjectechartsBox" style="height:100%;width:100%"></div>
</template>
<script>
import Echarts from 'echarts';
export default {
  props: ['option'],
  methods: {
    //实例化echarts
    initEcharts() {
      let myChart = Echarts.init(document.getElementById(`AllProjectechartsBox`));

      // 绘制图表
      myChart.setOption(this.option);
      if (this.option.series.length > 1) {
        myChart.on('click', params => {
          const getIdarr = this.option.series;
          let code;
          // eslint-disable-next-line array-callback-return
          getIdarr.map(item => {
            if (item.name === params.seriesName) {
              code = item.code;
            }
          });
          this.$emit('parentClick', {
            code,
            date: params.name,
            params,
            series: this.option.series,
          });
        });
      } else {
        // 点击事件
        const getIdarr = this.option.series[0].data;
        // console.log('getIdarr上层', this.option.series[0])
        // console.log('getIdarr', getIdarr);
        myChart.on('click', params => {
          //   console.log('2222222', params);
          this.$emit('parentClick', {
            code: getIdarr[params.dataIndex].code,
            date: params.name,
            projectCode: this.option.code,
          });
        });
      }
    },
  },
  mounted() {
    this.initEcharts();
  },
};
</script>
<style lang="scss" scoped></style>
